<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="azhuo" uri="/WEB-INF/tld/commons.tld"%>
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>客户管理</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/AdminLTE.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/bootstrap.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/css/font-awesome.css">
</head>

<body>
	<jsp:include page="/WEB-INF/jsp/head.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/jsp/aside.jsp"></jsp:include>

	<!-- 内容区域 -->
	<div class="content-wrapper">

		<!-- 内容头部 -->
		<section class="content-header">
			<h1>客户管理</h1>
			<ol class="breadcrumb">
				<li><a href="index.html"> <i class="fa fa-dashboard"></i>
						首页
					</a></li>
				<li class="active">客户管理</li>
			</ol>
		</section>
		<!-- 内容头部 /-->

		<!-- 正文区域 -->
		<section class="content">

			<!-- .box-body -->
			<div class="box box-primary">
				<div class="box-header with-border">

					<form action="${pageContext.request.contextPath }/toCustomer.action">
						<input type="hidden" name="page" value="1" /> <input type="hidden" name="size" value="5" />

						<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
							<tr>
								<td>客户名称</td>
								<td><input type="text" name="cust_name" class="form-control" placeholder="客户名称" value="${cust_name }">
								</td>
								<td>客户来源</td>
								<td><select name="cust_source" class="form-control" style="height: 36px">
										<option value="">请选择</option>
										<c:forEach items="${fromType }" var="item">
											<option value="${item.dict_id }" <c:if test="${item.dict_id == cust_source}">selected</c:if>>
												${item.dict_item_name }</option>
										</c:forEach>
									</select></td>
								<td>所属行业</td>
								<td><select name="cust_industry" class="form-control" style="height: 36px">
										<option value="">请选择</option>
										<c:forEach items="${industryType }" var="item">
											<option value="${item.dict_id }" <c:if test="${item.dict_id == cust_industry}">selected</c:if>>
												${item.dict_item_name }</option>
										</c:forEach>
									</select></td>
								<td>客户级别</td>
								<td><select name="cust_level" class="form-control" style="height: 36px">
										<option value="">请选择</option>
										<c:forEach items="${levelType }" var="item">
											<option value="${item.dict_id }" <c:if test="${item.dict_id == cust_level}">selected</c:if>>
												${item.dict_item_name }</option>
										</c:forEach>
									</select></td>
								<td><input type="submit" value="查询" class="btn bg-olive btn-default" /></td>
							</tr>
						</table>
					</form>
				</div>

				<div class="box-body">

					<!-- 数据表格 -->
					<div class="table-box">

						<!--工具栏-->
						<div class="pull-left">
							<div class="form-group form-inline">
								<div class="btn-group">
									<a href="${pageContext.request.contextPath }/toAddCustomer.action" class="btn btn-default bg-olive">新建</a>
								</div>
							</div>
						</div>
						<!--工具栏/-->

						<!--数据列表-->
						<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
							<thead>
								<tr>
									<th class="sorting_asc">编号</th>
									<th class="sorting_desc">客户名称</th>
									<th class="sorting_desc">客户来源</th>
									<th class="sorting_asc sorting_asc_disabled">客户所属行业</th>
									<th class="sorting_desc sorting_desc_disabled">客户级别</th>
									<th class="sorting">固定电话</th>
									<th class="text-center sorting">手机</th>
									<th class="text-center">操作</th>
								</tr>
							</thead>
							<tbody>
								
								<c:forEach items="${page.rows }" var="row">
									<tr>
										<td>${row.cust_id}</td>
										<td>${row.cust_name}</td>
										<td>${row.cust_source}</td>
										<td>${row.cust_industry}</td>
										<td>${row.cust_level}</td>
										<td>${row.cust_phone}</td>
										<td class="text-center">${row.cust_mobile}</td>
										<td class="text-center">
											<a href="${pageContext.request.contextPath }/toUpdateCustomerPage.action?cust_id=${row.cust_id}" class="btn bg-olive btn-xs">修改</a>
											<%-- 
												<a href="${pageContext.request.contextPath }/deleteCustomer.action?cust_id=${row.cust_id}" class="btn bg-olive btn-xs" onclick="javascript:return check('${row.cust_name}')">删除</a>
												<button type="button" class="btn bg-olive btn-xs">修改</button>
											--%>
											<button type="button" class="btn bg-olive btn-xs" onclick="deleteCustomer(${row.cust_id},'${row.cust_name}')">删除</button>
										</td>
									</tr>
								</c:forEach>

							</tbody>

						</table>
						<!--数据列表/-->

					</div>
					<!-- 数据表格 /-->
				</div>
				<!-- /.box-body -->

				<!-- .box-footer-->
				<div class="box-footer">
					<div class="pull-left">
						<div class="form-group form-inline">
							<!-- 没有数据 -->
							<c:if test="${empty page.rows}">
								共 ${page.total } 条数据。
							</c:if>

							<!-- 有数据 -->
							<c:if test="${!empty page.rows}">
								<c:choose>
									<c:when test="${page.total < page.size }">
										共查询到 ${page.total } 条数据，每页 ${page.total } 条，总共 ${page.pageCount } 页。
									</c:when>
									<c:otherwise>
										共查询到 ${page.total } 条数据，每页 ${page.size } 条，总共 ${page.pageCount } 页。
									</c:otherwise>
								 </c:choose>
							</c:if>
						</div>
					</div>

					<div class="box-tools pull-right">
						<ul class="pagination">
							<azhuo:page url="${pageContext.request.contextPath }/toCustomer.action" />
						</ul>
					</div>

				</div>
				<!-- /.box-footer-->

			</div>

		</section>
		<!-- 正文区域 /-->

	</div>
	<!-- 内容区域 /-->

	<script>
		
		// 发送删除客户异步请求
		function deleteCustomer(cust_id, cust_name) {
			var flag = confirm('你确认要删除"' + cust_name + '"客户吗？');
			console.log("flag = " + flag);
			if (flag) {
				$.post(
					"${pageContext.request.contextPath }/deleteCustomer.action",
					{ "cust_id": cust_id },
					function (data) {
						if (data == "OK") {
							alert("成功删除客户：" + cust_name);
							window.location.reload();
						} else {
							alert("删除失败");
							window.location.reload();
						}
					}
				);
			}
			return flag;
		}
		// function check(cust_name) {
		// 	var flag = confirm('你确认要删除"' + cust_name + '"客户吗？');
		// 	console.log("flag = " + flag);
		// 	return flag;
		// }
	</script>

</body>

</html>